package com.marktotop.file.service.impl;

import com.marktotop.file.entity.TbUser;
import com.marktotop.file.mapper.LoginMapper;
import com.marktotop.file.response.ResultBean;
import com.marktotop.file.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author WXLD
 * @data 2021/4/19 - 15:44
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    @Override
    public int login(String username, String password) {
        TbUser oneByUserName = loginMapper.getOneByUserName(username);
        if (oneByUserName != null){
            String daoPass = oneByUserName.getPassword();
            if(password.equals(daoPass)){
                //传入的密码与数据库密码一致
                return 2;
            }
            return 1;
        }
        return 0;
    }

    @Override
    public TbUser getUserProfile(String username) {
        TbUser userByName = loginMapper.findUserByName(username);
        userByName.setPassword("");
        return userByName;
    }
}
